#!/usr/bin/env gawk -f
# Transfor an .npart.4 file to a .part file suitable for showme

# See triangle -h and the manual of metis for the corresponding formats

# Output format: 
#	First line: <# of elements> <# of domains (starting from 1)>
#	Remaining lines: <element #> <domain #>

# Input format:
#	All lines: <domain # (starting from 0)>: ith line represents the ith node

# BUG: Dont know how to handle 2 times the same file (to automatically get the number of domains)
# So, please enter yourself the number of domains as the second number on the first line
# (printed as a comment at the end of the file, just in case)

# For the wrekagrid project, Basile Clout


BEGIN{print "#ofnodes\t#ofdomains"}	# First line ...

$1 > d {d=$1}	#update the number of domains 
{	print "\t" ++x "\t"$1+1; 	}	#Add the element id at the beginning of all lines, and add 1 to the domain id

END{print "#Number of nodes = " NR "\t# Number of domains = " d+1}
